﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Sora.HelpSystem.Viewer.Converters
{
    public class StringToUriConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var uri = value as Uri;

            return uri != null ? uri.AbsoluteUri : String.Empty;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                string val = value as string;

                return String.IsNullOrEmpty(val) ? null : new Uri(val);
            }
            catch
            {
                return null;
            }
        }

        #endregion
    }
}
